<?php
namespace Admin\Controller;
use Think\Controller;
use Common\Common\Tree;
class JobController extends Controller {
    /**
    职位设置
     **/
    public function indexAction(){
        $model = M();
        $sql = "select * from jobs";
        $job = $model->query($sql);
//        var_dump($job);
        $this->assign('job',$job);
        $this->display('index');
    }


    /**
    职位修改
     **/
    public function jobmodifyAction(){

        $job_list = I('post.job_list');

        foreach ($job_list as $k => $v) {

            $sql = "update jobs set name='{$v}' where id='{$k}'";

            $model = M();

            $model->execute($sql);

        }
        $this->success('修改成功',U('Admin/Job/index'),2);
    }

    /**
    职位删除
     **/
    public function jobdeleteAction(){
        $id = I('get.id');
//        var_dump($id);
        $sql = "delete from jobs where id='{$id}'";
        $model = M();
        $model->execute($sql);
        $this->success('删除成功',U('Admin/Job/index'),2);



    }

    /**
    职位添加
    **/
    public function jobaddAction(){
        $jobs = I('post.jobs');
//        var_dump($jobs);
        if(!empty($jobs)){
            $jobsArr = array();
            $jobsArr = explode("\n",$jobs);
            foreach ($jobsArr as $value) {
                $value = trim($value);
                $model = M();
                $sql = "insert into jobs (name) VALUE ('$value')";
                $model->execute($sql);
            }
            $this->success('添加成功',U('Admin/Job/index'),2);
        }else{
            $this->error('未添加任何内容','',2);
        }


    }
}